package page_rank

import (
	"fmt"
	"strings"
)

type tPage struct {
	id string
	weight float64
	links []IPage
}

func NewPage(id string) IPage {
	return &tPage{
		id: id,
		weight: 0,
		links: []IPage{},
	}
}

func (me *tPage) ID() string {
	return me.id
}

func (me *tPage) GetWeight() float64 {
	return me.weight
}

func (me *tPage) SetWeight(w float64) {
	me.weight = w
}

func (me *tPage) GetLinks() []IPage {
	return me.links
}

func (me *tPage) AddLink(p IPage) {
	me.links = append(me.links, p)
}

func (me *tPage) String() string {
	linkStrings := make([]string, len(me.links))
	for i,p := range me.links {
		linkStrings[i] = p.ID()
	}
	return fmt.Sprintf("p(%v, %8.4f, [%v])", me.id, me.weight, strings.Join(linkStrings, " "))
}

